{
  description = "Description for the project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
    nixpkgs-new.url = "github:NixOS/nixpkgs/nixos-25.05";
  };

  outputs = inputs@{ flake-parts, nixpkgs-new, ... }:
    flake-parts.lib.mkFlake { inputs = inputs; } {
      systems = [ "x86_64-linux" "aarch64-darwin" ];
      perSystem = { config, self', inputs', pkgs, system, ... }:
        let
          pkgs-new = import nixpkgs-new {
            inherit system;
          };
          arch-cmd = pkgs.writeShellScriptBin "arch" ''
            uname -m
          '';
          clang_15 = pkgs.llvmPackages_15.clang;

          cjc-sysroot = pkgs.symlinkJoin {
            name = "cjc-sysroot";
            paths = with pkgs; [
              pkgs-new.glibc
              pkgs-new.stdenv.cc.cc
            ];
          };

          wrap-cjc = pkgs.writeShellScriptBin "wrap-cjc" ''
            . ${pkgs.makeWrapper}/nix-support/setup-hook

            wrapProgram $1 \
                --append-flags "-B${cjc-sysroot}/lib" \
                --append-flags "--link-option -I${cjc-sysroot}/lib/ld-linux-x86-64.so.2" # For non NixOS
          '';
        in
        {
          devShells.default =
            let
              cjb = pkgs.writeShellScriptBin "cjb" (builtins.readFile ./cjb.sh);
            in
            pkgs.mkShell {
              hardeningDisable = [ "all" ];
              buildInputs = with pkgs; [
                python3
                cmake
                ninja
                pkgs-new.lldb

                pkgs-new.clang-tools
                clang_15

                libxcrypt
                openssl

                gtest
                libffi

                # $(arch) is used in envsetup.sh
                arch-cmd

                cjb
                # Xren
                # pkgs-new.gdbgui
              ];

              shellHook = ''
                if [ -z ''${CANGIE_HOME:-} ]; then
                    if [ -f cangjie_compiler/output/envsetup.sh ]; then
                       . cangjie_compiler/output/envsetup.sh 
                    fi
                fi

                if [ -e $PWD/cangjie_stdx/target/ ]; then
                    PLATFORM=$(ls $PWD/cangjie_stdx/target/)
                    export CANGJIE_STDX_PATH="$PWD/cangjie_stdx/target/$PLATFORM/dynamic/stdx"
                    export LD_LIBRARY_PATH="$CANGJIE_STDX_PATH:$LD_LIBRARY_PATH"
                fi

                export CJ_ROOT="$PWD"

                export JOBS=$(nproc --all)
              '';

              CC = "${clang_15}/bin/clang";
              CXX = "${clang_15}/bin/clang++";

              # To use with cjc: cjc -B $TOOLCHAIN
              TOOLCHAIN = "${cjc-sysroot}/lib";

              # For cjc to link binaries with right glibc version
              LIBRARY_PATH = "${cjc-sysroot}/lib";

              NIX_CJC_ARGS = "-B${cjc-sysroot}/lib --link-option -I${cjc-sysroot}/lib/ld-linux-x86-64.so.2";
              NIX_WRAP_CJC = "${wrap-cjc}/bin/wrap-cjc";

              # TODO: scripts
              # cangjie_tools/cjpm $ python3 build/build.py clean
              # cangjie_tools/cjpm $ python3 build/build.py build -t debug
              # cangjie_tools/cjpm $ python3 build/build.py install --prefix $CANGJIE_HOME/tools/bin/
              #
              # cangjie_tools/cangjie-language-server $ python3 build/build.py clean
              # cangjie_tools/cangjie-language-server $ python3 build/build.py build -t release -j32
              # cangjie_tools/cangjie-language-server $ python3 build/build.py install --prefix $CANGJIE_HOME/tools/bin/
            };
        };
      flake = { };
    };
}
